﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime .InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;

namespace LearnCSharp
{
	class ProcessusCSharp : System.Windows.Forms.Form
	{
		[DllImport("user32.dll")]
		//[DllImport("user32.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
		public static extern bool SetForegroundWindows(IntPtr hWnd);

		static public void Test()
		{
			
			Process processus = new Process();
			processus.StartInfo.FileName = "iexplore.exe";
			processus.StartInfo.Arguments = "http://www.google.com";
			processus.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
			processus.Start();
			processus.Close(); //Libère les ressources (ne détruit pas le processus) 
			
			/*
			Process p;

			p = new Process();
			p.StartInfo.FileName = "Notepad.exe";
			p.StartInfo.Arguments = "xyz.txt";
			p.Start();
						
			SetForegroundWindows(p.MainWindowHandle);
			SendKeys.Send("Salut c'est moi !");
			SendKeys.Send("^S");
			*/
		}
	}

	class ThreadCSharp
	{
		public static void Test()
		{
			Console.WriteLine("Début du programme");

			// Création des thread et affectation de leur fonction
			Thread t1 = new Thread(new ThreadStart(f));
			Thread t2 = new Thread(new ThreadStart(g));

			// Lancement des threads
			t1.Start();
			t2.Start();

			// Le thread principal attend la fin des threads enfants
			// sinon "Fin de programme" sera fficher avant la fin de l'execution des threads
			t1.Join();
			t2.Join();

			Console.WriteLine("Fin du programme");
		}

		static void f()
		{
			for(int i=0;i<10;i++) Console.WriteLine("fff"+i+"FFF");
		}

		static void g()
		{
			for (int i = 0; i < 50; i++) Console.WriteLine("ggg" + i + "GGG");
		}
	}
}
